package com.example.demo.aop;

import com.google.gson.Gson;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Aspect
@Component
public class  HLogAspect {
    @Pointcut("@annotation(com.example.demo.annotion.ULog)")
    public  void annotationPointCut() {
    }

    @Before("annotationPointCut()")
    public void before(JoinPoint joinPoint){
        MethodSignature sign =  (MethodSignature)joinPoint.getSignature();
        Method method = sign.getMethod();
        System.out.print("接受方法："+method.getName()+" 前置日志");
        System.out.println("Request Args   : {}" +  new Gson().toJson(joinPoint.getArgs()));
    }
}
